package main

import (
	"fmt"
	"os"
	"time"
)

func main() {

	//ch := make(chan int, 1)
	//for i := 0; i < 10; i++ {
	//	select {
	//	case x := <-ch:
	//		fmt.Println(x) // "0" "2" "4" "6" "8"
	//	case ch <- i:
	//	}
	//}

	abort := make(chan struct{})
	go func() {
		os.Stdin.Read(make([]byte, 1)) // read a single byte
		abort <- struct{}{}
	}()

	fmt.Println("Commencing countdown.  Press return to abort.")
	//tick := time.Tick(1 * time.Second)
	ticker := time.NewTicker(1 * time.Second)
	for countdown := 10; countdown > 0; countdown-- {
		fmt.Println(countdown)
		select {
		case i := <-ticker.C:
			fmt.Println(" i=" + i.String())
			// Do nothing.
		case <-abort:
			fmt.Println("Launch aborted!")
			return
		}
	}
	ticker.Stop()
	fmt.Println("lanuch....")
}
